﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace PeachLite.Helpers
{
    public static class BizHelper
    {
        public static Random R = new Random();
        public static string GetSerial(int code)
        {
            string serial = "";
            switch (code)
            {
                case 1:
                    serial = GetUnixTime(DateTime.Now).ToString();
                    break;
                case 2:
                    serial = GetLongTime(DateTime.Now).ToString();
                    break;
                case 3:
                    serial = Guid.NewGuid().ToString();
                    break;
                case 4:
                    serial = DateTime.Now.ToString("yyyyMMddHHmmss") + R.Next(100, 999).ToString();
                    break;
                default:
                    serial = DateTime.Now.ToString("yyyyMMddHHmmss");
                    break;
            }
            return serial;
        }

        public static int GetUnixTime(DateTime time)
        {
            DateTime startTime = new DateTime(1970, 1, 1);
            TimeSpan ts = time - startTime;
            return (int)ts.TotalSeconds;
        }

        public static long GetLongTime(DateTime time)
        {
            DateTime startTime = new DateTime(1970, 1, 1);
            TimeSpan ts = time - startTime;
            return (long)ts.TotalMilliseconds;
        }
    }
}